
package com.hlkj.pay.controller.common;

import cn.hutool.core.bean.BeanUtil;
import com.hlkj.framework.common.pojo.CommonResult;
import com.hlkj.framework.common.pojo.PageResult;
import com.hlkj.framework.common.util.collection.CollectionUtils;
import com.hlkj.pay.controller.BaseController;
import com.hlkj.pay.dto.common.OperatedLogPageDto;
import com.hlkj.pay.dto.common.OperatedLogPageQueryDto;
import com.hlkj.pay.service.common.IOperatedLogService;
import com.hlkj.pay.vo.common.req.OperatedLogPageReq;
import com.hlkj.pay.vo.common.resp.OperatedLogListResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;

/**
 * Description: 模板基础接口
 *
 * @author monk@techsun.com
 * @date 2023/3/23
 */
@Tag(name = "轨迹日志")
@RestController
@RequestMapping("/v1/common")
@RequiredArgsConstructor
public class OperatedController extends BaseController {


    private final IOperatedLogService operatedLogService;

    @Operation(summary = "轨迹日志")
    @GetMapping("/operated/logs")
    CommonResult<PageResult<OperatedLogListResp>> logs(OperatedLogPageReq operatedLogPageReq) {
        OperatedLogPageQueryDto operatedLogPageQueryDto = BeanUtil.copyProperties(operatedLogPageReq, OperatedLogPageQueryDto.class);
        processQueryDate(operatedLogPageReq, operatedLogPageQueryDto);
        PageResult<OperatedLogPageDto> page = operatedLogService.queryPage(operatedLogPageQueryDto);
        List<OperatedLogPageDto> list = page.getList();
        if (CollectionUtils.isEmpty(list)) {
            return buildPageResult(page, Collections.emptyList());
        }
        return buildPageResult(page, list);
    }
}
